package com.qzsoft.zhjd.materiel.modules.materieldata.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.materiel.modules.materieldata.dto.MaterielDataDetailsDto;
import com.qzsoft.zhjd.materiel.modules.materieldata.service.MaterielDataService;

/**
 * @ClassName MaterielDataController
 * @Description 物料磅单数据详情
 * @author linhuawei
 * @since 2022-04-01
 */
@RestController
@RequestMapping("/api/materielData")
public class MaterielDataController {

    @Autowired
    private MaterielDataService materielDataService;
    
    /**
     * @Title details
     * @Description 获取磅单详情
     * @param id 磅单主键
     * @return 磅单详情
     */
    @GetMapping("/details")
    public Result<MaterielDataDetailsDto> details(@RequestParam(required = true) String id) {
        MaterielDataDetailsDto data = materielDataService.getDetailsById(id);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getLastYear
     * @Description 获取最新一条数据年份
     * @return 最新一条数据年份
     */
    @GetMapping("/getLastYear")
    public Result<String> getLastYear(@RequestParam Map<String, Object> params) {
        String year = materielDataService.getLastYear(params);
        return ResultUtils.ok(year);
    }

    /**
     * @Title getYearList
     * @Description 获取有生产数据的年份
     * @return 有生产数据的年份
     */
    @GetMapping("/getYearList")
    public Result<List<String>> getYearList(@RequestParam Map<String, Object> params) {
        List<String> data = materielDataService.getYearList(params);
        return ResultUtils.ok(data);
    }

}
